package org.xiaojinlong.thread;

/**
 * @author Jin Long
 * 2015/9/20
 */
public class LockAndNotLock {
    private static class TaskA implements Runnable {
        @Override
        public void run() {
            while (true) {
                a();
                Thread.yield(); //
                b();
            }
        }
    }

    private static int i, j;

    private synchronized static void a() {
        i++; j++;
    }

    private synchronized static void b() {
        if (i != j)
            System.out.println("@" + i + "---@" + j);
    }

    public static void main(String[] args) {
        Thread t1 = new Thread(new TaskA());
        Thread t2 = new Thread(new TaskA());
        t1.start(); t2.start();
    }
}
